package beautiful.butterfly.drds.binlog.operation;


import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

@Slf4j
public class OpeationEventQueue
{
    // 专门存储各种事件
    // poll: 若队列为空，返回null。
    // remove:若队列为空，抛出NoSuchElementException异常。
    // take:若队列为空，发生阻塞，等待有元素。

    // put---无空间会等待
    // add--- 满时,立即返回,会抛出异常
    // offer---满时,立即返回,不抛异常


    public static BlockingQueue<OpeationEvent> objectQueue = new LinkedBlockingQueue<OpeationEvent>();

    public static void addObject(OpeationEvent opeationEvent)
    {
        try
        {
            objectQueue.put(opeationEvent);
        } catch (InterruptedException e)
        {
            log.error("fail to put event into operation queue" + e.toString());
        }
    }

    ;

    public static OpeationEvent getObject()
    {
        return objectQueue.poll();
    }

}